package com.eascs.fp.uc.server.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.fp.common.dto.MemberDTO;
import com.eascs.fp.common.entity.MemberEntity;
import com.eascs.fp.common.vo.ModelResult;
import com.eascs.fp.uc.dao.MemberDao;
import com.eascs.fp.uc.server.MemberService;

@Service
public class MemberServiceImpl implements MemberService{
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private MemberDao memberDao;

	@Override
	public ModelResult<MemberEntity> queryMemberEntity(MemberEntity entity) {
		ModelResult<MemberEntity> modelResult=new ModelResult<>();
		try {
			MemberEntity model=memberDao.queryMemberEntity(entity);
			modelResult.withModel(model);
			return modelResult;
		} catch (Exception e) {
			logger.info("member.error.queryMemberEntity(),exception:{}", e.getMessage());
		}
		return modelResult.withError("member.error.queryMemberEntity()", "查询失败!");
	}

	@Override
	public ModelResult<Boolean> updateMemberEntity(MemberEntity entity) {
		ModelResult<Boolean> modelResult=new ModelResult<>();
		try {
			Boolean model=memberDao.updateMemberEntity(entity);
			modelResult.withModel(model);
			return modelResult;
		} catch (Exception e) {
			logger.info("member.error.updateMemberEntity(),exception:{}", e.getMessage());
		}
		return modelResult.withError("member.error.updateMemberEntity()", "修改失败!");
	}

	@Override
	public ModelResult<MemberEntity> insertMemberEntity(MemberEntity entity) {
		ModelResult<MemberEntity> modelResult=new ModelResult<>();
		try {
			MemberEntity model=memberDao.insertMemberEntity(entity);
			modelResult.withModel(model);
			return modelResult;
		} catch (Exception e) {
			logger.info("member.error.insertMemberEntity(),exception:{}", e.getMessage());
		}
		return modelResult.withError("member.error.insertMemberEntity()", "插入失败!");
	}

	@Override
	public ModelResult<PageResult<Object[]>> queryMemberPage(MemberDTO dto) {
		ModelResult<PageResult<Object[]>> modelResult=new ModelResult<>();
		try {
			PageResult<Object[]> model=memberDao.queryMemberPage(dto);
			modelResult.withModel(model);
			return modelResult;
		} catch (Exception e) {
			logger.info("member.error.queryMemberPage(),exception:{}", e.getMessage());
		}
		return modelResult.withError("member.error.queryMemberPage()", "查询失败!");
	}

}
